package FlowJob;


import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

// 4.1.1 无限缓冲区流水线作业问题 F2||Cmax
public class F2Cmax {
    static class Artifact{
        int id;
        int process;
        int process2;
        @Override
        public String toString() {
            return "J" + id + "{" +
                "p1=" + process +
                ", p2=" + process2 +
                '}';
        }
    }
    private static final int machines = 2;
    int[] process;
    List<Artifact> am,am1,am2;
    public void solve(){
        if(process==null){
            process = new int[]{4,4,30,6,2,5,1,4,30,3};
        }
        int n = process.length;
        am = new ArrayList<>();
        am1 = new ArrayList<>();
        am2 = new ArrayList<>();
        for (int i=0;i<n/machines;i++){
            //第一台机器上所需的加工时间
            int p1 = process[i];
            //第二台机器上所需的加工时间
            int p2 = this.process[i + n / machines];
            Artifact a = new Artifact();
            a.id = (i+1);
            a.process = p1;
            a.process2 = p2;
            if(p1 < p2){
                am1.add(a);
            }else {
                am2.add(a);
            }
            am1.sort(Comparator.comparingInt(o -> o.process));
            am2.sort(Comparator.comparingInt(o -> -o.process2));
        }
        am.addAll(am1);
        am.addAll(am2);
        System.out.println("最优排序：" + am);
    }
}
